package logic

import (
	"context"
	"home/homerpc/homerpc"

	"home/api/internal/svc"
	"home/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ResterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewResterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResterLogic {
	return &ResterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ResterLogic) Rester(req *types.ResterRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	rester, err := l.svcCtx.HomeRpc.Rester(l.ctx, &homerpc.ResterRequest{
		Tel:      req.Tel,
		Password: req.Password,
	})
	if err != nil {
		return &types.Response{
			Message: "注册失败",
			Code:    500,
			Data:    nil,
		}, nil
	}

	return &types.Response{
		Message: "注册成功",
		Code:    200,
		Data:    rester,
	}, nil
}
